﻿using ReadyApps.Wiki;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace ReadyAppsTest
{
    [TestClass()]
    public class EffectivePermissionsTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Constructor Tests

        [TestMethod]
        public void EffectivePermissionsConstructorTest()
        {
            EffectivePermissions target = new EffectivePermissions();
            PrivateObject targetWrapper = new PrivateObject(target);
            Assert.AreEqual(WikiPermissions.None, (WikiPermissions)targetWrapper.GetField("permissions"));
        }

        #endregion

        #region Private Method Tests

        [TestMethod]
        public void GetPermissionTest()
        {
            EffectivePermissions target = new EffectivePermissions();
            PrivateObject targetWrapper = new PrivateObject(target);
            bool expected = false;
            bool actual = (bool)targetWrapper.Invoke("GetPermission", WikiPermissions.ViewPage);
            Assert.AreEqual(expected, actual);

            expected = true;
            target.ViewPage = expected;
            actual = (bool)targetWrapper.Invoke("GetPermission", WikiPermissions.ViewPage);
            Assert.AreEqual(expected, actual);

            target.EditPermissions = false;
            actual = (bool)targetWrapper.Invoke("GetPermission", WikiPermissions.ViewPage);
            Assert.AreEqual(expected, actual);

            target.EditPermissions = true;
            actual = (bool)targetWrapper.Invoke("GetPermission", WikiPermissions.ViewPage);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void SetPermissionTest()
        {
            EffectivePermissions target = new EffectivePermissions();
            PrivateObject targetWrapper = new PrivateObject(target);
            bool expected = false;
            Assert.AreEqual(expected, target.ViewPage);

            expected = true;
            targetWrapper.Invoke("SetPermission", WikiPermissions.ViewPage, true);
            Assert.AreEqual(expected, target.ViewPage);
        }

        #endregion

        #region Property Tests

        [TestMethod]
        public void EditPermissionsTest()
        {
            EffectivePermissions target = new EffectivePermissions();
            Assert.AreEqual(false, target.EditPermissions);
            bool expected = true;
            bool actual;
            target.EditPermissions = expected;
            actual = target.EditPermissions;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void NonSecurityEnabledPermissionsTest()
        {
            EffectivePermissions actual;
            actual = EffectivePermissions.NonSecurityEnabledPermissions;
            Assert.AreEqual(true, actual.ViewPage);
            Assert.AreEqual(false, actual.EditPermissions);
        }

        [TestMethod]
        public void ViewPageTest()
        {
            EffectivePermissions target = new EffectivePermissions();
            Assert.AreEqual(false, target.ViewPage);
            bool expected = true;
            bool actual;
            target.ViewPage = expected;
            actual = target.ViewPage;
            Assert.AreEqual(expected, actual);
        }

        #endregion
    }
}
